#include <vector>

using namespace std;

class Solution
{
public:
    int removeDuplicates(vector<int> &nums)
    {
        if (nums.size() < 3)
        {
            return nums.size();
        }
        int begin = 2,end = 2;
        while (end < nums.size())
        {
            if (nums[begin - 2] != nums[end])
            {
                nums[begin] = nums[end];
                ++begin;
            }
            ++end;
        }
        return begin;
    }
};